require 'rubygems' #It seems this must be early required
require 'sqlite3'
require 'fileutils'

require 'main_view'
require 'main_controller'

JATIT_DIR = File.expand_path('~/.jatit')
JATIT_DATABASE_FILE_NAME = 'jatit.db'
JATIT_DATABASE_FILE_PATH = File.join(JATIT_DIR, JATIT_DATABASE_FILE_NAME)


def create_database
	if !FileTest.file?(JATIT_DATABASE_FILE_PATH)
		FileUtils.mkdir(JATIT_DIR) if !FileTest.directory?(JATIT_DIR)
		db = SQLite3::Database.new( JATIT_DATABASE_FILE_PATH )
		File.open('create.sql') {|file| db.execute_batch(file.read)}
	end
	ActiveRecord::Base.establish_connection(:adapter => "sqlite3" ,:dbfile => JATIT_DATABASE_FILE_PATH)
end


create_database()


main_controller = MainController.new
main_controller.init
main_controller.main_view = MainWin.new(nil, "main window")
main_controller.run

